package ch.fhnw.kosmonauten.client.gui;

import java.awt.Color;
import java.awt.Graphics;

/**
 * Diese Klasse stellt das Hexagram dar.
 * 
 * @author Fabian Siegrist
 * @author Oliver Freiermuth
 * @author Mikhail Onoufrienko
 * @author Risto Milani
 * @version $Revision: 154 $
 *          File name: $HeadURL: http://iching-kosmonauten.googlecode.com/svn/I-Ching/src/ch/fhnw/kosmonauten/client/gui/Hexagram.java $
 *          Last modified:$Date: 2013-05-26 02:43:14 +0000 (Sun, 26 May 2013) $
 *          Last modified by: $Author: molotok.mihon@gmail.com $
 */

// class definition
public class Hexagram extends javax.swing.JPanel {

	// attributes
	private final int[] lines;
	private final int start_vertical;
	private final int start_horisont;

	// constructors
	/**
	 * @param lines
	 * @param vertical
	 * @param horizontal
	 */
	public Hexagram(int[] lines, int vertical, int horizontal) {
		this.lines = lines;
		this.start_vertical = vertical;
		this.start_horisont = horizontal;
		initComponents();
	}

	public int[] getLines() {
		return lines;
	}
	
	// methods
	/*
	 * @see javax.swing.JComponent#paint(java.awt.Graphics)
	 */
	@Override
	public void paint(Graphics g) {
		super.paint(g);
		int start = this.start_vertical;
		this.drawLine(this.lines[0], start, start_horisont, g);
		start += 30;
		this.drawLine(this.lines[1], start, start_horisont, g);
		start += 30;
		this.drawLine(this.lines[2], start, start_horisont, g);
		start += 30;
		this.drawLine(this.lines[3], start, start_horisont, g);
		start += 30;
		this.drawLine(this.lines[4], start, start_horisont, g);
		start += 30;
		this.drawLine(this.lines[5], start, start_horisont, g);

	}

	/*
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 */
	@Override
	public void paintComponent(Graphics g) {
		super.paint(g);
		int start = this.start_vertical;
		this.drawLine(this.lines[0], start, start_horisont, g);
		start += 30;
		this.drawLine(this.lines[1], start, start_horisont, g);
		start += 30;
		this.drawLine(this.lines[2], start, start_horisont, g);
		start += 30;
		this.drawLine(this.lines[3], start, start_horisont, g);
		start += 30;
		this.drawLine(this.lines[4], start, start_horisont, g);
		start += 30;
		this.drawLine(this.lines[5], start, start_horisont, g);

	}

	/**
	 * @param g
	 */
	private void setRectColor(Graphics g) {
		g.setColor(Color.RED);
	}

	/**
	 * @param g
	 */
	private void setLineColor(Graphics g) {
		g.setColor(Color.BLACK);
	}

	/**
	 * @param type
	 * @param startpoint
	 * @param horisont
	 * @param g
	 */
	private void drawLine(int type, int startpoint, int horisont, Graphics g) {
		this.setRectColor(g);
		switch (type) {
		case 6:
			g.fillRect(horisont, startpoint, 90, 20); // LINKS,OBEN,LAENGE,HOEHE
			this.setLineColor(g);
			g.drawLine(horisont + 90, startpoint, horisont + 110,
					startpoint + 20);
			g.drawLine(horisont + 90, startpoint + 20, horisont + 110,
					startpoint);
			this.setRectColor(g);
			g.fillRect(horisont + 110, startpoint, 90, 20);
			break;
		case 7:
			g.fillRect(horisont, startpoint, 200, 20);
			break;
		case 8:
			g.fillRect(horisont, startpoint, 90, 20); // LINKS,OBEN,LAENGE,HOEHE
			g.fillRect(horisont + 110, startpoint, 90, 20);
			break;
		case 9:
			g.fillRect(horisont, startpoint, 200, 20);
			this.setLineColor(g);
			g.drawOval(horisont + 90, startpoint, 20, 20);
			break;
		}
	}

	/**
	 * Creates new form Hexagram
	 * 
	 * @param type
	 */
	public void initComponents(int type) {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		setBorder(javax.swing.BorderFactory
				.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 396,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 296,
				Short.MAX_VALUE));
	}
	// </editor-fold> Variables declaration - do not modify.
	// End of variables declaration
}
